package com.atguigu.eduorder.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.commonutils.R;
import com.atguigu.eduorder.client.CourseClient;
import com.atguigu.eduorder.entity.Order;
import com.atguigu.eduorder.entity.OrderVO;
import com.atguigu.eduorder.mapper.OrderMapper;
import com.atguigu.eduorder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-06-16
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private CourseClient courseClient;

    @Override
    public void createOrder(OrderVO orderVO) {
        String courseId = orderVO.getCourseId();
        String memberId = orderVO.getMemberId();
        Map<String, Object> data = courseClient.getCourseInfo(courseId).getData();
        if (!CollectionUtils.isEmpty(data)) {

            Map<String, Object> courseInfoVo = (Map<String, Object>) data.get("courseInfoVo");
            if (!CollectionUtils.isEmpty(courseInfoVo)) {

                String title = (String) courseInfoVo.get("title");
                String cover = (String) courseInfoVo.get("cover");
                Object price = courseInfoVo.get("price");
                String teacherId = (String) courseInfoVo.get("teacherId");
                System.out.println(title + "=" + cover + "=" + price + "=" + teacherId);
            }

        }

    }
}
